package com.sunday.haowushop.ui.order;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.sunday.common.base.BaseActivity;
import com.sunday.common.model.ResultDO;
import com.sunday.common.utils.ToastUtils;
import com.sunday.haowushop.R;
import com.sunday.haowushop.entity.GroupBuyOrder;
import com.sunday.haowushop.http.ApiClient;
import com.sunday.haowushop.ui.WebViewActivity;

import java.math.RoundingMode;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by 刘涛 on 2017/6/27.
 */

public class GroupRefundDetailActivity extends BaseActivity{



    @Bind(R.id.title_view)
    TextView titleView;

    @Bind(R.id.money)
    TextView money;
    @Bind(R.id.reason)
    TextView reason;
    @Bind(R.id.time)
    TextView time;

    private GroupBuyOrder order;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_check_refund_detail);
        ButterKnife.bind(this);
        order= (GroupBuyOrder) getIntent().getSerializableExtra("order");
        titleView.setText("退货详情");
        money.setText(String.format("¥%s",order.getTotalFee().setScale(2, RoundingMode.HALF_UP)));
        reason.setText(order.getReason());
        time.setText(order.getBackTime());
    }


    @OnClick({R.id.btn_1,R.id.btn_2})
    void onClick(View v){
        switch (v.getId()){
            case R.id.btn_1:
                //撤销申请
                showLoadingDialog(0);
                Call<ResultDO> call = ApiClient.getApiAdapter().cancelRefund(order.getId());
                call.enqueue(new Callback<ResultDO>() {
                    @Override
                    public void onResponse(Call<ResultDO> call, Response<ResultDO> response) {
                        if (isFinish || response.body() == null) {
                            return;
                        }
                        dissMissDialog();
                        if (response.body().getCode() == 0) {
                            ToastUtils.showToast(mContext, "已撤销申请");
                            finish();
                        } else {
                            ToastUtils.showToast(mContext, response.body().getMessage());
                        }
                    }

                    @Override
                    public void onFailure(Call<ResultDO> call, Throwable t) {
                        dissMissDialog();
                        ToastUtils.showToast(mContext, R.string.network_error);
                    }
                });
                break;
            case R.id.btn_2:
                //
                intent = new Intent(mContext, WebViewActivity.class);
                intent.putExtra("url", "https://kefu.easemob.com/webim/im.html?tenantId=41555");
                intent.putExtra("title", "客服");
                startActivity(intent);
                break;
        }
    }

}
